<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>北京联合大学</title>
</head>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://at.alicdn.com/t/font_835526_xufba1hg66.css">
<link rel="stylesheet" href="../..//css/Initialization.css">
<link rel="stylesheet" href="../..//css/commen.css">
<link rel="stylesheet" href="../..//css/password.css">
<link rel="stylesheet" href="../../css/UploadResults.css">
<body>
<div id="content">
    <div class="initer">
        <!-- 具体内容 -->
        <div class="bread">
            <div class="plain">管理配置</div>
            <div class="plain">
                <i class="iconfont icon-right"></i>
            </div>
            <div class="plain current"><a href="../depart/stuclasslist" style="color: #0057a8;">学生信息管理</a></div>
            <div class="plain">
                <i class="iconfont icon-right"></i>
            </div>
            <div class="plain current">导入学生信息</div>

            <div class="center-button" id="importStudentInfo">下载模版</div>
        </div>
        <div class="modifypassword" style="margin-top: 50px;">
            <div class="modifyinput">
                <span class="text">学年名称：</span>
                <select id="gradeid">
                    <option value="0">请选择</option>
                    <option th:each="item:${grade}" th:value="${item.id}" th:text="${item.departname}" th:selected="${depart.pid == item.id}"></option>
                </select>
            </div>
            <div class="modifyinput">
                <span class="text">班级名称：</span>
                <select id="departid">
                    <option value="0">请选择</option>
                    <option th:each="item:${classdepart}" th:value="${item.id}" th:text="${item.departname}" th:selected="${depart.id == item.id}"></option>
                </select>
            </div>
            <div class="modifyinput">
                <span class="text">导入文件</span>
                <input type="file" name="file" id="file"/>
            </div>
            <div class="modifyinput">
                <span class="center-button" id="subBut">导入学生信息</span>
                <span class="center-button" onclick="history.back()">返回</span>
            </div>
        </div>
    </div>
</div>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/commen.js"></script>
<script>
    $(function () {
        $("#gradeid").change(function () {
            var departid = $(this).val();
            $.ajax({
                type : "POST",
                url : "../depart/getDepartByPid",
                data : {departid: departid},
                dataType : "json",
                success : function(data) {
                    $("#departid").empty();
                    $("#departid").append("<option value=\"0\">请选择</option>");
                    var json = $.parseJSON(data.data);
                    for(var i=0;i<json.length;i++){
                        $("#departid").append("<option value=\""+json[i].id+"\">"+json[i].departname+"</option>");
                    }
                },
                error:function(msg){
                    alert("程序出错，请联系管理员");
                }
            });
        });

        $("#importStudentInfo").click(function () {
            location.href = "/files/models/studentmodel.xls";
        });

        $("#subBut").click(function () {
            var departid = $("#departid").val()
            var formData = new FormData();
            formData.append("file", document.getElementById("file").files[0]);
            formData.append("departid", departid);
            $.ajax({
                url: "upStudentInfo",
                type: "POST",
                data: formData,
                contentType: false,
                processData: false,
                dataType:"json",
                success: function (data) {
                    alert(data.result);
                    if(data.state == success){
                        location.reload();
                    }
                },
                error: function () {
                    alert("上传失败！");
                }
            });
        })
    })
</script>
</body>
</html>

